package com.rz.paas.test.inChannel.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.rz.paas.test.inChannel.bottomMenuFragment.ChannelSettingFragment
import com.rz.paas.test.inChannel.bottomMenuFragment.ProcessDataFragment
import com.rz.paas.test.inChannel.bottomMenuFragment.StreamingSettingFragment
import com.rz.paas.test.inChannel.bottomMenuFragment.UserInformationFragment

const val CHANNEL_SETTING_INDEX = 0
const val STREAMING_SETTING_INDEX = 1
const val USER_INFORMATION_INDEX = 2
const val PROCESS_DATA_INDEX = 3

class PagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
    private val tabFragmentsCreators: Map<Int, () -> Fragment> = mapOf(
        CHANNEL_SETTING_INDEX to { ChannelSettingFragment() },
        STREAMING_SETTING_INDEX to { StreamingSettingFragment() },
        USER_INFORMATION_INDEX to { UserInformationFragment() },
        PROCESS_DATA_INDEX to { ProcessDataFragment() },
    )

    override fun getItemCount(): Int {
        return tabFragmentsCreators.size
    }

    override fun createFragment(position: Int): Fragment {
        return tabFragmentsCreators[position]?.invoke() ?: throw IndexOutOfBoundsException()
    }
}